//
//  WSSendMealTimeSectionHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/6.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "WSSendMealTimeSectionHeaderView.h"
@interface WSSendMealTimeSectionHeaderView()
/**灰色线8px*/
@property (nonatomic, strong) UIView *lightGrayLineView;

/**bgView 添加手势*/
@property (nonatomic, strong) UIView *bgView;
/**送餐地址Lb*/
@property (nonatomic, strong) UILabel *nameLb;
/**加号图片*/
@property (nonatomic, strong) UIImageView *iconIv;
/**新增lb*/
@property (nonatomic, strong) UILabel *addLb;

@end

@implementation WSSendMealTimeSectionHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView
{
    [self.contentView addSubview:self.bgView];
    [self.contentView addSubview:self.lightGrayLineView]; //线
    
    [self.bgView addSubview:self.nameLb];
    
    [self.bgView addSubview:self.iconIv];
    [self.bgView addSubview:self.addLb];
}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    //线
    [self.lightGrayLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(8);
    }];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.lightGrayLineView.mas_bottom);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-1);
    }];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.height.mas_offset(22);
        make.right.equalTo(self.iconIv.mas_left);
    }];
    
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.right.equalTo(self.addLb.mas_left);
    }];
    [self.addLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 20));
        make.centerY.equalTo(self.bgView.mas_centerY);
        make.right.equalTo(self.bgView.mas_right).offset(-10);
    }];
}


#pragma mark - getter
- (UIView *)lightGrayLineView {
    if (!_lightGrayLineView) {
        _lightGrayLineView = [[UIView alloc] init];
        _lightGrayLineView.backgroundColor = kMainLightGrayColor;
    }
    return _lightGrayLineView;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAddTapGes:)];
        [_bgView addGestureRecognizer:tapGes];
    }
    return _bgView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        //国际化
        NSString *scaddressStr = NSLocalizedString(DeliveryAddress, @"送餐地址");
        _nameLb.text = scaddressStr;
    }
    return _nameLb;
}

- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"加"]];
    }
    return _iconIv;
}

- (UILabel *)addLb {
    if (!_addLb) {
        _addLb = [[UILabel alloc] init];
        //国际化
        NSString *addStr = NSLocalizedString(AddNew, @"新增");
        _addLb.text = addStr;
    }
    return _addLb;
}

- (void)clickAddTapGes:(UITapGestureRecognizer *)tap {
//    [JRToast showWithText:@"新加收货地址"];
    FDLog(@"2019-2-25点击了 新加收货地址");
    
    if (self.wsSendSendMealTimeSectionHeaderViewClickAddBlock) {
        self.wsSendSendMealTimeSectionHeaderViewClickAddBlock();
    }
}


@end
